package EX02_Account;

import java.util.Scanner;

public class AccountService implements IAccountService {

	private AccountDAO adao = new AccountDAO();
	
	
	@Override
	public void createAccount() {
	
		System.out.println("1.계좌개설");
		Scanner sc = new Scanner(System.in);
		AccountVO a = new AccountVO();
		
		System.out.println("계좌번호를 입력하세요");
		a.setAid(sc.next());
		System.out.println("잔고를 확인하세요");
		a.setBalance(sc.nextInt());
		System.out.println("이메일을 입력하세요");
		a.setEmail(sc.next());
		
		if(adao.insertAccount(a))
			System.out.println("계좌 개설이 완료되었습니다");
		else
		System.out.println("입력 오류! 계좌 개설에 실패했습니다.");
		
	}

	@Override
	public void readAccount() {
	for(AccountVO a : adao.selectAccount()){
		System.out.println(a.getAno());
		System.out.println("/");
		System.out.println(a.getAid());
		System.out.println("/");
		System.out.println(a.getBalance());
		System.out.println("/");
		System.out.println(a.getEmail());
		System.out.println("/");
		System.out.println(a.getDateCreated());
	}
	
	}

	@Override
	public void modifyAccount() {
	readAccount();
	AccountVO avo = new AccountVO();
	Scanner sc = new Scanner(System.in);
	System.out.println("잔액을 확인하세요");
	avo.setBalance(sc.nextInt());
	if(adao.updateAccount(avo)){
		System.out.println("입/출금 확인 성공!");
	}else
		System.out.println("입/출금 확인 실패 ㅠ_ㅠ");
	
	}

	@Override
	public void deleteAccount() {
		readAccount();
		AccountVO avo = new AccountVO();
		Scanner sc = new Scanner(System.in);
		System.out.println("삭제할 계좌의 번호를 입력하세요");
		avo.setAno(sc.nextInt());
		if(adao.deleteAccount(avo)){
			System.out.println("계좌가 정상적으로 삭제되었습니다.");
		}else
			System.out.println("계좌가 삭제되지 않았어요. 다시 시도해주세요");
		
	}


	
}
